package cn.tedu.front.search.service.impl;

import cn.tedu.common.pojo.vo.PageData;
import cn.tedu.front.search.dao.persist.repository.IJobRepository;
import cn.tedu.front.search.dao.search.IJobCustomSearchRepository;
import cn.tedu.front.search.dao.search.IJobSearchRepository;
import cn.tedu.front.search.pojo.po.JobSimplePO;
import cn.tedu.front.search.service.IJobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class JobService implements IJobService {
    @Autowired
    private IJobRepository repository;

    @Autowired
    private IJobCustomSearchRepository customSearchRepository;

    @Autowired
    private  IJobSearchRepository jobSearchRepository;
    @Override
    public void saveJob(){
        log.info("开始把JobPO写进ES............");
        Integer pageNum=1;
        Integer pageSize=10;
        PageData<JobSimplePO> poPageData = repository.listSearchJob(pageNum, pageSize);
        List<JobSimplePO> list = poPageData.getList();
        for (JobSimplePO simplePO : list) {
            customSearchRepository.save(simplePO);
        }
    }

    @Override
    public PageData<JobSimplePO> getJob(String keyword, Integer pageNum, Integer pageSize) {
        log.info("开始处理【搜索职位】的业务，关键词：{}, 页码：{}，每页记录数：{}\""+keyword,pageNum,pageSize);
        PageData<JobSimplePO> pageData = jobSearchRepository.jobSearch(keyword, pageNum, pageSize);
        return pageData;
    }
}
